package com.qd.common.sys.domain.entity.role;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author sjk
 * 角色
 */
@EqualsAndHashCode(callSuper = false)
@Getter
@Setter
public class RoleDTO extends BaseQuery implements Serializable {
    @JsonIgnore
    @ExcelIgnore
    private static final String EXCEL_TITLE = "角色信息";
    /**
     * 主键
     */
    @ExcelProperty(value = {EXCEL_TITLE, "角色ID"})
    @NotBlank(message = "角色ID不能为空", groups = UpdateGroup.class)
    @Size(max = 50, message = "角色ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String roleId;
    /**
     * 父级角色ID
     */
    @ExcelIgnore
    @Size(max = 50, message = "父级ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String roleParentId;
    /**
     * 角色编码
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*角色编码"})
    @NotBlank(message = "角色编码不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "角色编码长度不能超过{max}位", groups = DefaultGroup.class)
    private String roleCode;
    /**
     * 角色名称
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*角色名称"})
    @NotBlank(message = "角色名称不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "角色名称长度不能超过{max}位", groups = DefaultGroup.class)
    private String roleName;
    /**
     * 角色序号
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*角色序号"})
    @NotNull(message = "角色序号不能为空", groups = DefaultGroup.class)
    private Integer roleSort;
    /**
     * 角色状态:0正常 1停用
     */
    @ExcelIgnore
    @NotNull(message = "角色状态不能为空", groups = DefaultGroup.class)
    private Integer roleStatus;
    /**
     * 角色状态显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*角色状态"})
    private String roleStatusDisplay;
    /**
     * 数据权限
     */
    @ExcelIgnore
    @NotBlank(message = "数据权限不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "数据权限长度不能超过{max}位", groups = DefaultGroup.class)
    private String dataScope;
    /**
     * 数据权限显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*数据权限"})
    private String dataScopeDisplay;
    /**
     * 备注
     */
    @ExcelProperty(value = {EXCEL_TITLE, "备注"})
    @Size(max = 200, message = "备注长度不能超过{max}位", groups = DefaultGroup.class)
    private String remark;
    /**
     * 添加时间
     */
    @ExcelProperty(value = {EXCEL_TITLE, "添加时间"})
    private LocalDateTime addTime;
    /**
     * 修改时间
     */
    @ExcelProperty(value = {EXCEL_TITLE, "修改时间"})
    private LocalDateTime updateTime;
    /**
     * 子角色列表
     */
    @ExcelIgnore
    private List<RoleDTO> children;
    /**
     * 角色对应的菜单信息
     */
    @ExcelIgnore
    private List<String> menuList;

    @Override
    public void freeData() {
        this.roleId = null;
        this.roleParentId = null;
        this.roleCode = null;
        this.roleName = null;
        this.roleSort = null;
        this.roleStatus = null;
        this.roleStatusDisplay = null;
        this.remark = null;
        this.dataScope = null;
        this.dataScopeDisplay = null;
        this.addTime = null;
        this.updateTime = null;
        if (children != null) {
            children.clear();
        }
        if (menuList != null) {
            menuList.clear();
        }
        super.freeData();
    }
}
